using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using BLL;
using Public;

namespace QLNhanKhau
{
    public partial class frmQuanHe : DevComponents.DotNetBar.Metro.MetroForm
    {
        public frmQuanHe()
        {
            InitializeComponent();
        }

        int MaNK;
        int MaSHK;

        public frmQuanHe(int MaNK, int MaSHK)
        {
            InitializeComponent();
            this.MaNK = MaNK;
            this.MaSHK = MaSHK;
        }

        private void frmQuanHe_Load(object sender, EventArgs e)
        {
            cmbQuanHe.DataSource = QuanHeBLL.LoadQuanHe();
            cmbQuanHe.DisplayMember = "TenQuanHe";
            cmbQuanHe.ValueMember = "MaQH";

            cmbNguoiCap.DataSource = NguoiDungBLL.LoadNguoiCap();
            cmbNguoiCap.DisplayMember = "HoTen";
            cmbNguoiCap.ValueMember = "MaND";

            dateNgayCap.Value = DateTime.Now;

            cmbCanBoDangKi.Text = frmDangNhap.user_login.HoTen;

            txtChucVu.Text = ChucVuBLL.LoadChucVuByMaCV(NguoiDungBLL.LoadNguoiDungByMaND((int)cmbNguoiCap.SelectedValue).MaCV).TenChucVu;
            txtChucVu.Enabled = false;

            txtNoiChuyen.Text = MaSHK.ToString();
            txtSoChuyenKhau.Text = DungChung.LoadMaCDi().ToString();
        }

        private void btnXong_Click(object sender, EventArgs e)
        {
            NhanKhauBLL.UpdateQuanHe(MaNK, (byte)cmbQuanHe.SelectedValue);
            NhanKhauBLL.UpdateMaSHK(MaSHK, MaNK);

            ChuyenKhauPublic ck = new ChuyenKhauPublic();
            ck.MaNK = MaNK;
            ck.MaCK = DungChung.LoadMaCDi();
            ck.SoChuyenKhau = int.Parse(txtSoChuyenKhau.Text);
            ck.NoiChuyen = txtNoiChuyen.Text;
            ck.LyDoChuyen = txtLyDoChuyen.Text;
            ck.NgayNhan = dateNgayCap.Value;
            ck.NgayCap = dateNgayCap.Value;
            ck.CanBoNoiChuyen = cmbCanBoDangKi.Text;
            ck.CanBoNoiNhan = cmbCanBoDangKi.Text;
            ck.NguoiCap = cmbNguoiCap.Text;
            ck.NguoiNhan = cmbNguoiCap.Text;
            ck.ChucVuNguoiChuyen = txtChucVu.Text;
            ck.ChucVuNguoiNhan = txtChucVu.Text;
            ck.NoiCap = int.Parse(ThietLapBLL.LoadMaDiaChi());
            ChuyenKhauBLL.InsertChuyenKhau(ck);
            //frmChuyenDi cd = new frmChuyenDi();
            //cd.Refresh();
            this.Close();
            MessageBox.Show("Chuyển khẩu thành công");
            
        }

        private void cmbNguoiCap_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void cmbNguoiCap_SelectionChangeCommitted(object sender, EventArgs e)
        {
            txtChucVu.Text = ChucVuBLL.LoadChucVuByMaCV(NguoiDungBLL.LoadNguoiDungByMaND((int)cmbNguoiCap.SelectedValue).MaCV).TenChucVu;
        }
       
    }
}